package jmine.tec.persist.jms.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import jmine.tec.persist.annotation.Alias;
import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.utils.date.Timestamp;

/**
 * Entidade para persistir mensagens de monitoramento/diagnostico recebidas via JMS.
 * 
 * @author queiroz
 */
@Entity
@Table(name = "JMS_MONIT_MESSAGE")
@Alias("JMOMSG")
@SequenceGenerator(name = "SEQ_JMOMSG", sequenceName = "SEQ_JMOMSG")
@Documentation("ARMAZENA MENSAGENS DE MONITORAMENTO JMS")
public class JMSMonitoringMessage extends PersistableBusinessObject {

    private static final short MAX_LENGTH = 1000;

    private Long id;

    private String sendQueueJndi;

    private String receiveMDB;

    private String connectionFactoryJndi;

    private String sendMqQueue;

    private String receiveMqQueue;

    private Timestamp sendTimestamp;

    private Timestamp receiveTimestamp;

    private Timestamp putTimestamp;

    private String errorMessage;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_JMOMSG")
    @Column(name = "COD_JMS_MONIT_MSG", nullable = false)
    @Documentation("CODIGO DA MENSAGEM JMS MONITORADA.")
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the queueJndi
     */
    @Column(name = "SEND_QUEUE_JNDI", length = MAX_LENGTH)
    @Documentation("JNDI DA FILA DE ENVIO.")
    public String getSendQueueJndi() {
        return sendQueueJndi;
    }

    /**
     * @param queueJndi the queueJndi to set
     */
    public void setSendQueueJndi(String queueJndi) {
        this.sendQueueJndi = queueJndi;
    }

    /**
     * @return the connectionFactoryJndi
     */
    @Column(name = "CONNECTION_FACTORY_JNDI", length = MAX_LENGTH)
    @Documentation("JNDI DA CONNECTION FACTORY.")
    public String getConnectionFactoryJndi() {
        return connectionFactoryJndi;
    }

    /**
     * @param connectionFactoryJndi the connectionFactoryJndi to set
     */
    public void setConnectionFactoryJndi(String connectionFactoryJndi) {
        this.connectionFactoryJndi = connectionFactoryJndi;
    }

    /**
     * @return the mqQueueName
     */
    @Column(name = "SEND_MQ_QUEUE", length = MAX_LENGTH)
    @Documentation("FILA NO MQ DE ENVIO.")
    public String getSendMqQueue() {
        return sendMqQueue;
    }

    /**
     * @param mqQueueName the mqQueueName to set
     */
    public void setSendMqQueue(String mqQueueName) {
        this.sendMqQueue = mqQueueName;
    }

    /**
     * @return the sendTimestamp
     */
    @Column(name = "TS_MSG_SEND")
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    @Documentation("TIMESTAMP NA QUAL A MENSAGEM FOI ENVIADA.")
    public Timestamp getSendTimestamp() {
        return sendTimestamp;
    }

    /**
     * @param sendTimestamp the sendTimestamp to set
     */
    public void setSendTimestamp(Timestamp sendTimestamp) {
        this.sendTimestamp = sendTimestamp;
    }

    /**
     * @return the putTimestamp
     */
    @Column(name = "TS_MSG_PUT")
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    @Documentation("TIMESTAMP NA QUAL A MENSAGEM POSTADA NA FILA.")
    public Timestamp getPutTimestamp() {
        return putTimestamp;
    }

    /**
     * @param putTimestamp the putTimestamp to set
     */
    public void setPutTimestamp(Timestamp putTimestamp) {
        this.putTimestamp = putTimestamp;
    }

    /**
     * @return the receiveTimestamp
     */
    @Column(name = "TS_MSG_RECEIVE")
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    @Documentation("TIMESTAMP NA QUAL A MENSAGEM CHEGOU.")
    public Timestamp getReceiveTimestamp() {
        return receiveTimestamp;
    }

    /**
     * @param receiveTimestamp the receiveTimestamp to set
     */
    public void setReceiveTimestamp(Timestamp receiveTimestamp) {
        this.receiveTimestamp = receiveTimestamp;
    }

    /**
     * @return the errorMessage
     */
    @Column(name = "ERROR_MSG", length = 10485760)
    @Type(type = "org.hibernate.type.TextType")
    @Documentation("DETALHE DO ERRO.")
    public String getErrorMessage() {
        return errorMessage;
    }

    /**
     * @param errorMessage the errorMessage to set
     */
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    /**
     * @return the receiveQueueJndi
     */
    @Column(name = "RECEIVE_MDB", length = MAX_LENGTH)
    @Documentation("MDB DE RECEBIMENTO DA MENSAGEM.")
    public String getReceiveMDB() {
        return receiveMDB;
    }

    /**
     * @param receiveQueueJndi the receiveQueueJndi to set
     */
    public void setReceiveMDB(String receiveQueueJndi) {
        this.receiveMDB = receiveQueueJndi;
    }

    /**
     * @return the receiveMqQueueName
     */
    @Column(name = "RECEIVE_MQ_QUEUE", length = MAX_LENGTH)
    @Documentation("FILA NO MQ DE RECEBIMENTO.")
    public String getReceiveMqQueue() {
        return receiveMqQueue;
    }

    /**
     * @param receiveMqQueueName the receiveMqQueueName to set
     */
    public void setReceiveMqQueue(String receiveMqQueueName) {
        this.receiveMqQueue = receiveMqQueueName;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        StringBuffer str = new StringBuffer();
        str.append("\nTeste de Mensagens:");
        str.append("\n\tConnection Factory: " + this.connectionFactoryJndi);
        str.append("\n\tJNDI da fila de envio: " + this.sendQueueJndi);
        str.append("\n\tFila de envio no MQ: " + this.sendMqQueue);
        str.append("\n\tData/hora de envio: " + this.sendTimestamp);
        str.append("\n\t------------------------------------------------------------------------------------------");
        str.append("\n\tMDB de recebimento: " + this.receiveMDB);
        str.append("\n\tFila de recebimento no MQ: " + this.receiveMqQueue);
        str.append("\n\tData/hora de recebimento: " + this.receiveTimestamp);
        str.append("\n\tData/hora de postagem da mensagem na fila: " + this.putTimestamp);
        str.append("\n\t------------------------------------------------------------------------------------------");
        if (this.errorMessage != null) {
            str.append("\n\tErros: " + this.errorMessage);
            str.append("\n\t------------------------------------------------------------------------------------------");
        }
        return str.toString();
    }

}
